package com.cao.meet.activity;

import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.blankj.utilcode.util.LogUtils;
import com.cao.meet.R;
import com.cao.meet.util.AppendFileWrite;

public class WriteFileActivity extends AppCompatActivity implements View.OnClickListener {

    private AppendFileWrite fileWrite;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_write_file);
        fileWrite = AppendFileWrite.getAppendFileWrite();
        final Button first_to_write = (Button) findViewById(R.id.first_to_write);
        first_to_write.setOnClickListener(this);
        final Button second_to_write = (Button) findViewById(R.id.second_to_write);
        second_to_write.setOnClickListener(this);
        final Button third_to_write = (Button) findViewById(R.id.third_to_write);
        third_to_write.setOnClickListener(this);
        final Button read_form_txt = (Button) findViewById(R.id.read_form_txt);
        read_form_txt.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.first_to_write:
                LogUtils.e(Environment.getExternalStorageDirectory().getPath()+"Environment.getExternalStorageDirectory().getPath()+\"/cao.txt\"");
                fileWrite.writeToFile(Environment.getExternalStorageDirectory().getPath()+"/hello.txt","第一次输入的内容",getApplicationContext());
                break;
            case R.id.second_to_write:
                fileWrite.writeToFile(Environment.getExternalStorageDirectory().getPath()+"/hello.txt","第二次输入的内容",getApplicationContext());
                break;
            case R.id.third_to_write:
                fileWrite.writeToFile(Environment.getExternalStorageDirectory().getPath()+"/hello.txt","第三次输入的内容",getApplicationContext());
                break;
            case R.id.read_form_txt:
                String fromFile = fileWrite.readFromFile(Environment.getExternalStorageDirectory().getPath() + "/hello.txt");
                LogUtils.e(fromFile);
                break;
        }
    }
}
